import asyncio
import time


# 创建一个协程任务
async def task1():
    print("task 1 开始")
    await asyncio.sleep(2)
    print("task 1 结束")
    return "task 1 结果"

# 创建一个协程任务
async def task2():
    print("task 2 开始")
    await asyncio.sleep(1)
    print("task 2 结束")
    return "task 2 结果"

async def main():
    # 创建任务并立即运行
    task_1 = asyncio.create_task(task1())
    task_2 = asyncio.create_task(task2())

    # 等待任务完成
    result_1 = await task_1
    result_2 = await task_2
    print(result_1, result_2)

start_time = time.time()
# 运行主协程
asyncio.run(main())
print("总耗时：", time.time() - start_time)